<?php
/**
 * Notes:行政管理-消息中心
 * User: xiangzi
 * Date: 2025/7/14
 * Time: 下午4:04
 */

namespace App\Timer;

use App\Models\administration\MsgModel;
use App\Models\StaffModel;

class Tips
{

    /**
     * Notes:员工转正、生日、合同到期提示
     * User: xiangzi
     * Date: 2025/7/14
     * Time: 下午5:24
     * @return void
     */
    public function index()
    {
        $staff = StaffModel::where('status', 1)->get();

        $insert = [];
        foreach ($staff as $value) {
            //转正员工
            if ($value->turn_date == date('Y-m-d')) {
                $date = date('Y年m月d日');
                $insert[] = [
                    'title' => '员工转正',
                    'type' => 1,
                    'content' => '员工【 ' . $value->name . '】于' . $date . '试用期结束，请知晓！',
                    'created_at' => date('Y-m-d H:i:s'),
                ];
            }
            //生日员工
            if (date('m-d', strtotime($value->birth_date)) == date('m-d')) {
                $date = date('Y年m月d日');
                $insert[] = [
                    'title' => '员工生日',
                    'type' => 2,
                    'content' => $date . '是员工【 ' . $value->name . '】的生日，请知晓！',
                    'created_at' => date('Y-m-d H:i:s'),
                ];
            }
            //员工到期
            if ($value->contract_end_date == date('Y-m-d')) {
                $date = date('Y年m月d日');
                $insert[] = [
                    'title' => '劳动合同期满',
                    'type' => 3,
                    'content' => '员工【 ' . $value->name . '】于' . $date . '劳动合同期满，请知晓！',
                    'created_at' => date('Y-m-d H:i:s'),
                ];
            }
        }

        if($insert){
            MsgModel::query()->insert($insert);
        }

    }

}